package osgi.common.services.job.client;


import org.osgi.service.component.ComponentContext;
import org.quartz.JobKey;

import osgi.common.services.EServiceState;
import osgi.common.services.client.AbstractService;
import osgi.common.services.job.IQuartzService;

public abstract class AbstractJobService extends AbstractService implements ICommonJob {


	protected IQuartzService quartz;
	protected JobKey jobKey;
	protected String jobName;
	protected String jobGroup;
	protected String cronExpression;


	
	
	
	
	
	public AbstractJobService() {
		super();
		
	}
	
	

	@Override
	public void bindQuartzService(IQuartzService service) {
		this.quartz = service;
		logger.info("Quartz BOUNDED !");
	}

	@Override
	public void unbindQuartzService(IQuartzService service) {
		this.quartz = null;

		this.setServiceState(EServiceState.INACTIVE);
		
		logger.info("Quartz LEFT THE BUILDING !");
	}

	
	
	
	@Override
	public void activate(ComponentContext context) {
		logger.info("activate(ComponentContext) - start");

		super.activate(context);

		if (this.quartz != null) {
			this.quartz.registerJob(this);
			logger.info("Registrou JOB no Quartz Service.");
		}

		logger.info("activate(ComponentContext) - end");
	}

	@Override
	public void deactivate(ComponentContext context) {
		if (this.quartz != null) {
			this.quartz.unregisterJob(this);
			logger.info("Desregistrou JOB no Quartz Service.");
		}
		super.deactivate(context);
	}

	
	

	@Override
	public String getJobName() {
		return this.jobName;
	}
	@Override
	public void setJobName(String jobName) {
		this.jobName = jobName;		
	}

	
	
	@Override
	public String getJobGroup() {
		return this.jobGroup;
	}
	@Override
	public void setJobGroup(String jobGroup) {
		this.jobGroup = jobGroup;		
	}

	
	
	
	@Override
	public void setJobKey(JobKey key) {
		this.jobKey = key;
		
	}

	@Override
	public JobKey getJobKey() {
		return this.jobKey;
	}

	@Override
	public String getCronExpression() {
		return this.cronExpression;
	}

	@Override
	public void setCronExpression(String cronExpression) {
		this.cronExpression = cronExpression;		
	}



	
	
	
}
